<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="time"></div>
    <div id="different_time">您已浏览该页面:0天0时0分0秒</div>
</body>
<script>
    var container = document.getElementById('time');
    var different_time = document.getElementById('different_time');

    //获取当前时间，并显示在界面
    var time = new Date();
    container.innerHTML = "您访问此页面的时间为:" + time.getFullYear() + "年"
                         + (time.getMonth() + 1) + "月"
                         + time.getDate() + "日"
                         + time.getHours() + "时"
                         + time.getMinutes() + "分"
                         + time.getSeconds() + "秒";

    //设置定时器                    
    setInterval(() =>{
        //获取访问页面时的时间戳
        let last_stamp = time.getTime();
        //获取当前时间的时间戳
        let now_stamp = new Date().getTime();
        let timeDifferent = now_stamp - last_stamp;
        //计算时间差的天数
        let day = Math.floor(timeDifferent / 1000 / 60 / 60 / 24 );
        //计算时间差的小时
        let hour = Math.floor(timeDifferent / 1000 / 60 / 60 % 24);
        //计算时间差的分钟
        let min = Math.floor(timeDifferent / 1000 / 60 % 60);
        //计算时间差的秒
        let second = Math.floor(timeDifferent / 1000 % 60);
        different_time.innerHTML = "您已浏览该页面:" + day + "天"
                                    + hour + "时"
                                    + min + "分"
                                    + second + "秒";
    },1000);
</script>
</html>